#ifndef _USTC_COMDEF_H_
#define _USTC_COMDEF_H_

#define RSP_SUCCESS		0

#define PACKED __packed
#define PACKED_REMOVED __packed

typedef unsigned char	USTC_U8;
typedef unsigned short  USTC_U16;
typedef unsigned long	USTC_U32;
typedef unsigned char	USTC_UCHAR;
typedef long			INT32;
typedef short			INT16;
typedef char			INT8;
typedef char			GS_CHAR;
typedef long long 		INT64;
typedef char			bool;
typedef USTC_U16 		STATUS_T;

typedef int				USTC_BOOL;

extern void outw(unsigned long addr, unsigned long val);
extern void outb(unsigned long addr, unsigned long val);
extern USTC_U32 inw(unsigned long addr);
extern USTC_U8 inb(unsigned long addr);

extern void ustc_outh(USTC_U16 index, USTC_U16 data);
extern USTC_U16 ustc_inh(USTC_U16 index);

extern void write_direct_32bit(USTC_U32 index, USTC_U32 data);
extern USTC_U32 read_direct_32bit(USTC_U32 index);

extern void write_indirect_32bit_Single(USTC_U32 index, USTC_U32 data);
extern USTC_U32 read_indirect_32bit_Single(USTC_U32 index);

#define inpb(port)       (*((volatile USTC_U8 *) (port)))
#define inpw(port)       (*((volatile USTC_U32 *) (port)))
#define inph(port)       (*((volatile USTC_U16 *) (port)))

#define outpb(port, val) (*((volatile USTC_U8 *) (port)) = ((USTC_U8) (val)))
#define outpw(port, val) (*((volatile USTC_U32 *) (port)) = ((USTC_U32) (val)))
#define outph(port, val) (*((volatile USTC_U16 *) (port)) = ((USTC_U16) (val)))

#if 1//(S3C44B0_TEST_PLATFORM==0)
#define USTC_IO_OUTW(io, val) 	ustc_io_outw((USTC_U16)(io), (val))
#define USTC_IO_OUTW2(io, val) 	ustc_io_outw2((USTC_U16)(io), (val))
#define USTC_IO_INW(io) 		ustc_io_inw((USTC_U16)(io))
#define USTC_IO_INW2(io) 		ustc_io_inw2((USTC_U16)(io))
#define USTC_IO_OUTB( io, val )	ustc_io_outb((USTC_U16)(io), (val))
#define USTC_IO_INB( io )		ustc_io_inb((USTC_U16)(io))

//#define MA_INH( io )		(USTC_U16)((io&2)?(read_indirect_32bit_Single((USTC_U32)io)>>16):read_indirect_32bit_Single((USTC_U32)io))
#define MA_INH( io )		(USTC_U16)ustc_io_inw((USTC_U32)io)
#else
	#if 0
	#define USTC_IO_OUTW( io, val )  	outpw( (io), (int) (val))
	#define USTC_IO_OUTW2( io, val ) 	outpw( (io), (int) (val))
	#define USTC_IO_OUTB( io, val ) 	outpb( (io), (int) (val))
	#define USTC_IO_INW( io )  			(USTC_U32) inpw( io )
	#define USTC_IO_INW2( io )  		(USTC_U32) inpw( io )
	#define USTC_IO_INB( io )  			(USTC_U8) inpb( io )
	#else
	#define USTC_IO_OUTW( io, val )		outw((USTC_U32)(io), (USTC_U32)(val))
	#define USTC_IO_OUTW2( io, val )	outw((USTC_U32)(io), (USTC_U32)(val))
	#define USTC_IO_OUTB( io, val )		outb((USTC_U32)(io), (USTC_U32)(val))
	#define USTC_IO_INW( io )			inw((USTC_U32)(io))
	#define USTC_IO_INW2( io )			inw((USTC_U32)(io))
	#define USTC_IO_INB( io )			inb((USTC_U32)(io))
	#endif
#define MA_INH( io )		(USTC_U16) inph( io )
#endif

#define USTC_IO_INWM( io, mask ) 	( USTC_IO_INW(io) & (mask) )
#define USTC_IO_INBM( io, mask )	( USTC_IO_INB(io) & (mask) )

#define NULL 0


#define USTC_IO_OUTBM( io, mask, val ) \
{\
  USTC_U16 temp;\
  (temp) =(((USTC_IO_INB(io) & (USTC_U8)(~(mask))) | ((USTC_U8)((val) & (mask)))));\
  ((void) USTC_IO_OUTB( io, temp));\
}\
  
#define USTC_IO_OUTWM( io, mask, val) \
{\
	USTC_U32 temp;\
	(temp) =(((USTC_IO_INW(io) & (USTC_U32)(~(mask))) |((USTC_U32)((val) & (mask)))));\
	USTC_IO_OUTW( io, (USTC_U32)(temp));\
}\
  
#endif  /*COMDEF_H*/
